package short_semester.questionnaire_planet.response.AnalyseController;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.NoArgsConstructor;
import short_semester.questionnaire_planet.pojo.*;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

@Data
@NoArgsConstructor
public class QAnalyseResponse {

    String questionnaireTitle;
    String description;
    Integer questionnaireCount = 0;
    @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    Date createdDate;
    @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    Date postDate;
    @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    Date latestPostDate;
    @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    Date closeDate;

    List<QuestionAlnalyseResponse> questions = new LinkedList<>();
    
    public void addQuestion(Object o){
        if(o instanceof SingleChoiceQuestion){
            
            questions.add(new QuestionAlnalyseResponse((SingleChoiceQuestion)o));
            
        }else if(o instanceof MultiChoiceQuestion){
            
            questions.add(new QuestionAlnalyseResponse((MultiChoiceQuestion) o));
            
        }else if(o instanceof FillBlankQuestion){
            
            questions.add(new QuestionAlnalyseResponse((FillBlankQuestion) o));
            
        }else if(o instanceof ScoreQuestion){
            
            questions.add(new QuestionAlnalyseResponse((ScoreQuestion) o));
            
        }
    }
    public QAnalyseResponse(Questionnaire questionnaire){
        questionnaireTitle = questionnaire.getTitle();
        description = questionnaire.getDescription();
        questionnaireCount = questionnaire.getCount();
        createdDate = questionnaire.getCreatedDate();
        postDate = questionnaire.getPostDate();
        latestPostDate = questionnaire.getLatestPostDate();
        closeDate = questionnaire.getCloseDate();
    }
}




